import {Component, ViewChild} from '@angular/core';
import { Storage } from '@ionic/storage';
// import { FlowType } from '../query/flowtype';

import {
  Events,
  AlertController,
  App,
  ModalController,
  NavController,
  NavParams,
  ActionSheetController,
  Content,
  ViewController,
  PopoverController
} from 'ionic-angular';

import {Config} from '../../../providers/config';
import { Common } from '../../../providers/common';

import _ from 'lodash';
import {FlowTypeService} from "./type.service";

@Component({
  selector: 'page-flow-type',
  templateUrl: './type.html',
  providers: [FlowTypeService]
})
export class FlowTypePage{
	moa_page_name: any = "page-flow-type";
  moa_page_explain: any = "流程类型";

  flowTypeDataSource = [];

  queryText = "";
  flowType = [];

  constructor(public alertCtrl: AlertController,
              public app: App,
              public modalCtrl: ModalController,
              public navCtrl: NavController,
              private navParams: NavParams,
              public events: Events,
              public config: Config,
              public actionSheetCtrl: ActionSheetController,
              public viewCtrl: ViewController,
              public storage: Storage,
              public popoverCtrl: PopoverController,
              public flowTypeService: FlowTypeService,
              // public flowType: FlowType,
              public common: Common) {
      // this.flowTypeDataSource = this.navParams.get("flowTypes");
      // this.flowType = this.flowTypeDataSource;
  }

  ionViewDidEnter() {
    let params = {};
    this.flowTypeService.getFlowTypes(params).subscribe(dataList => {
      if (dataList) {
        this.flowTypeDataSource = dataList;
        this.flowType = this.flowTypeDataSource;
      }
    })
  }

  cancel() {
    this.viewCtrl.dismiss("close");
  }

  typeRadioSelected(type) {
    this.viewCtrl.dismiss(type);
  }

  /**
   * 根据关键字更新列表数据
   */
  updateList() {
    if (this.queryText == "") {
      this.flowType = this.flowTypeDataSource;
    } else {
      this.flowType = [];
      _.forEach(this.flowTypeDataSource, flowType => {
        if (flowType.name.indexOf(this.queryText) != -1 ) {
          this.flowType.push(flowType);
        }
      });
    }
  }

}

